package 路径总和112;

/**
 * @author 谢阳
 * @version 1.8.0_131
 */
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {

    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        int val = root.val;
        if (root.right == null && root.left == null) {
            return targetSum == val;
        }

        return hasPathSum(root.left,targetSum - val) || hasPathSum(root.right,targetSum - val);
    }
}